﻿using IdentityService.Domain.Services;
using MediatR;

namespace IdentityService.Application.Commands
{
    public record CreateRoleCommand(string Name, string AppName, string Description) : IRequest<CreateRoleResultModel>;

    public class CreateRoleCommandHandler : IRequestHandler<CreateRoleCommand, CreateRoleResultModel>
    {
        private readonly IRoleService _roleService;
        public CreateRoleCommandHandler(IRoleService roleService)
            => _roleService = roleService;

        public async Task<CreateRoleResultModel> Handle(CreateRoleCommand request, CancellationToken cancellationToken)
        {
            return await _roleService.CreateRoleAsync(request.Name, request.AppName, request.Description);
        }
    }
}
